<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<table border="1">
			<tr><th>id</th><th>name</th><th>age</th></tr>
		</table>
		<script src="../js/jquery-3.5.1.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			$.post("http://localhost:8080/postdemo", {
				account: "hehe",
				password: "123"
			}, function(result, suc, response) {
				// console.log(result, suc, response); 
				// console.log(typeof result);
				let json = JSON.parse(result);
				console.log(json);
				//JQ对象.each才可以
				// json.each(function(index, item) {
				// 	console.log(index,item);
				// });
				//$.each(数组名, fn);JQ提供数组遍历函数
				$.each(json, function(index, item) {
					console.log(index,item);
					let tr = `<tr><td>${item.id}</td><td>${item.name}</td><td>${item.age}</td></tr>`;
					$("table").append(tr);
				});
				// myeach(json, function(index, item) {
				// 	console.log(index,item);
				// });
				// let tr = "";
				// $("table").append("<tr><td>Data1</td></tr>");
			});
			
			// function myeach(arr, fn) {
			// 	for(let index in arr) {
			// 		let item = arr[index];
			// 		fn(index, item);
			// 	}
			// }
		</script>
	</body>
</html>
